<template>
  <a-card :bordered="false">
    <div style="display: flex; justify-content: space-between">
      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <span>
          <a-button type="primary" icon="download" @click="handleExportXls('提现记录')">导出</a-button>
        </span>

        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
        </a-dropdown>
      </div>
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-form-item label="姓名" style="margin-right: 10px">
            <a-input
              placeholder="请输入用户姓名"
              v-model="queryParam.cardholderName"
              @pressEnter="searchQuery"
            ></a-input>
          </a-form-item>

          <a-form-item label="状态" style="margin-right: 10px">
            <a-select
              v-model="queryParam.status"
              style="width: 120px"
              :options="[
                { label: '待审核', value: '0' },
                { label: '通过', value: '1' },
                { label: '驳回', value: '2' }
              ]"
              allowClear
              placeholder="请选择"
              @change="searchQuery"
            />
          </a-form-item>
          <a-form-item label="用户id" style="margin-right: 10px">
            <a-input placeholder="请输入用户编号" v-model="queryParam.userId" @pressEnter="searchQuery"></a-input>
          </a-form-item>

          <a-form-item label="提现类型" style="margin-right: 10px">
            <a-select
              v-model="queryParam.withdrawalAccountType"
              style="width: 120px"
              :options="[
                { label: '支付宝', value: '1' },
                { label: '银行卡', value: '2' }
              ]"
              allowClear
              placeholder="请选择"
              @change="searchQuery"
            />
          </a-form-item>

          <a-form-item label="开始时间" style="margin-right: 10px">
            <a-date-picker v-model="queryParam.startTime" @change="startChange" :valueFormat="'YYYY-MM-DD'" />
          </a-form-item>
          <a-form-item label="结束时间" style="margin-right: 10px">
            <a-date-picker
              v-model="queryParam.endTime"
              @change="endChange"
              :valueFormat="'YYYY-MM-DD'"
              :disabled-date="disabledDate"
            />
          </a-form-item>
          <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
          </span>
        </a-form>
      </div>
    </div>
    <!-- table区域-begin -->
    <div class="ant-alert ant-alert-info" style="margin-bottom: 15px">
      <span style="margin-right: 20px"
        >已转帐金额：<span style="font-size: 16px; color: red">{{ parseFloat(isWithdrawAmount || 0).toFixed(2) }} </span
        >元</span
      >
      <span style="margin-right: 20px"
        >待转帐金额：<span style="font-size: 16px; color: red"
          >{{ parseFloat(notWithdrawAmount || 0).toFixed(2) }} </span
        >元</span
      >
    </div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      class="j-table-force-nowrap"
      @change="handleTableChange"
    >
      <span slot="action" slot-scope="text, record">
        <div v-if="record.status === 0">
          <a-popconfirm
            v-has="'xhdjuserWithdrawal:remittancetransfer'"
            title="确定通过吗?"
            @confirm="() => handlePass(record.id)"
          >
            <a>线下转账</a>
          </a-popconfirm>
          <a-divider type="vertical" />
          <a-popconfirm
            v-has="'xhdjuserWithdrawal:turndown'"
            title="确定驳回吗?"
            @confirm="() => handleReject(record.id)"
          >
            <a>驳回</a>
          </a-popconfirm>
        </div>
      </span>

      <template slot="avatarUrl" slot-scope="text, record">
        <div class="anty-img-wrap">
          <a-avatar shape="square" :src="record.avatarUrl" />
        </div>
      </template>
    </a-table>
    <!-- table区域-end -->
    <!-- 表单区域 -->
    <!-- <xhdjOrderInfo-modal ref="modalForm" @ok="modalFormOk"></xhdjOrderInfo-modal> -->
    <!-- <XhdjOrderInfoDialog ref="dialogForm"></XhdjOrderInfoDialog> -->
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
// import XhdjOrderInfoModal from './modules/XhdjOrderInfoModal'
import { getAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
// import XhdjOrderInfoDialog from './modules/XhdjOrderInfoDialog.vue'
export default {
  name: 'xhdjuserWithdrawal',
  mixins: [JeecgListMixin],
  // components: {
  //   XhdjOrderInfoModal,
  //   XhdjOrderInfoDialog
  // },
  data () {
    return {
      description: '订单表管理页面',
      options: [
        { label: '车费', value: '0' },
        { label: '服务', value: '1' },
        { label: '返佣', value: '2' }
      ],
      isWithdrawAmount: 0,
      notWithdrawAmount: 0,
      typeW: 2,
      // 表头
      columns: [
        {
          title: '序号',
          align: 'center',
          dataIndex: 'userId'
        },
        {
          title: '支付宝账号或者/银行卡账号',
          align: 'center',
          dataIndex: 'accountNumber'
        },
        {
          title: '提现金额',
          align: 'center',
          dataIndex: 'amount'
        },
        {
          title: '用户头像',
          align: 'center',
          dataIndex: 'avatarUrl',
          scopedSlots: { customRender: 'avatarUrl' }
        },
        {
          title: '持卡人姓名',
          align: 'center',
          dataIndex: 'cardholderName'
        },
        {
          title: '创建日期',
          align: 'center',
          dataIndex: 'createTime'
        },
        {
          title: '用户昵称',
          align: 'center',
          dataIndex: 'nickName'
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark'
        },
        {
          title: '状态', //1通过，0待审核，2驳回）
          align: 'center',
          dataIndex: 'status',
          customRender: (text, record) => {
            switch (record.status) {
              case 0:
                return '待审核'
                break
              case 1:
                return '通过'
                break
              case 2:
                return '驳回'
                break
            }
          }
        },
        {
          title: '更新日期',
          align: 'center',
          dataIndex: 'updateTime'
        },
        {
          title: '提现账号类型', //1支付宝，2银行卡)
          align: 'center',
          dataIndex: 'withdrawalAccountType',
          customRender: (text, record) => {
            switch (record.withdrawalAccountType) {
              case 1:
                return '支付宝'
                break
              case 2:
                return '银行卡'
                break
            }
          }
        },

        {
          title: '提现状态',
          align: 'center',
          dataIndex: 'withdrawalStatus',
          customRender: (text, record) => {
            switch (record.withdrawalStatus) {
              case 0:
                return '到账中'
                break
              case 1:
                return '已到账'
                break
              case 2:
                return '提现失败'
                break
            }
          }
        },

        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 150,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/user/xhdjUserWithdrawal/list',
        delete: '/xhdjOrderInfo/delete',
        passUrl: '/user/xhdjUserWithdrawal/pass',
        reject: 'user/xhdjUserWithdrawal/reject',
        statistics: '/user/xhdjUserWithdrawal/statistics',
        exportXlsUrl: '/user/xhdjUserWithdrawal/exportXls'
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  created () {
    this.init()
  },
  methods: {
    init () {
      var params = this.getQueryParams() //查询条件
      getAction(this.url.statistics, params).then(res => {
        if (res.success && res.result) {
          let { isWithdrawAmount, notWithdrawAmount } = res.result
          this.isWithdrawAmount = isWithdrawAmount
          this.notWithdrawAmount = notWithdrawAmount
        } else {
          this.isWithdrawAmount = 0
          this.notWithdrawAmount = 0
        }
      })
    },
    startChange (value) {
      if (value) {
        this.queryParam.startTime = value + ' 00:00:00'
      } else {
        this.queryParam.startTime = value
      }
    },
    endChange (value) {
      if (value) {
        this.queryParam.endTime = value + ' 23:59:59'
      } else {
        this.queryParam.endTime = value
      }
    },
    disabledDate (time) {
      return new Date(time).getTime() < new Date(this.queryParam.startTime).getTime()
    },
    // 通过
    handlePass (id) {
      getAction(this.url.passUrl, { id }).then(res => {
        if (res.code == 200) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.console.error(res.message)
        }
      })
    },
    handleReject (id) {
      getAction(this.url.reject, { id }).then(res => {
        if (res.code == 200) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.console.error(res.message)
        }
      })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
.ant-row {
  display: flex;
  justify-content: flex-end;
}
.ant-col {
  display: flex;
  justify-content: flex-end;
}
.ant-form {
  display: flex;
}
</style>
